//
//  ZWAudioTableViewCell.m
//  WanEr
//
//  Created by 高文萍 on 16/1/14.
//  Copyright © 2016年 ziwokeji. All rights reserved.
//

#import "ZWAudioTableViewCell.h"
#import "ZWHeader.h"
#import "ZWAudioTwiceTableCell.h"
@implementation ZWAudioTableViewCell
- (void)createData
{
    [self.twiceCellTable reloadData];
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.firstCellImg = [[UIImageView alloc]init];
        [self.contentView addSubview:self.firstCellImg];
        
        self.playerAllBut = [UIButton buttonWithType:UIButtonTypeCustom];
        [self addSubview:self.playerAllBut];
        
        self.cityPLabel = [[UILabel alloc]init];
        self.cityPLabel.font = [UIFont systemFontOfSize:14 weight:2];
        self.cityPLabel.textColor = [UIColor whiteColor];
        self.cityPLabel.textAlignment = NSTextAlignmentCenter;
        [self.contentView addSubview:self.cityPLabel];
        
        self.twiceCellTable = [[UITableView alloc]init];
        self.twiceCellTable.delegate = self;
        self.twiceCellTable.dataSource = self;
        [self.contentView addSubview:self.twiceCellTable];
        self.twiceCellTable.separatorStyle = UITableViewCellSeparatorStyleNone;// 取消分割线
        // 禁止滑动
        self.twiceCellTable.scrollEnabled = NO;
        self.twiceCellTable.showsVerticalScrollIndicator = NO;
        self.twiceCellTable.showsHorizontalScrollIndicator = NO;
        
        
        }
    return self;

}


- (void)layoutSubviews
{
    [super layoutSubviews];
    self.firstCellImg.frame = CGRectMake(15, 35, 70, 105 );
    [self.playerAllBut mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.firstCellImg.mas_left).offset(10);
        make.bottom.equalTo(self.firstCellImg.mas_bottom).offset(-5);
        make.width.height.equalTo(@(18));
    }];
    [self.cityPLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.firstCellImg.mas_centerY);
        make.centerX.equalTo(self.firstCellImg.mas_centerX);
    }];
    
    self.twiceCellTable.frame = CGRectMake(85 + 29, 20, CONTENTWIDTH - 85 - 29, self.twiceArr.count * 47 + 20);
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.twiceArr.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *reuseT = @"reuseT";
    ZWAudioTwiceTableCell *cellT = [tableView dequeueReusableCellWithIdentifier:reuseT];
    if (!cellT) {
        cellT = [[ZWAudioTwiceTableCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:reuseT];
    }
    cellT.selectionStyle = UITableViewCellSelectionStyleNone;//取消点重颜色
    NSString *str = @"、";
    cellT.cityLabel.text = self.twiceArr[indexPath.row][@"scenerie_name"];
    cellT.numLabel.text = [self.twiceArr[indexPath.row][@"serial"] stringByAppendingString:str];
    cellT.img.image = [UIImage imageNamed:@"Oval 41 + Oval 41 Copy + Oval 41 Copy 2 Copy Copy Copy Copy Copy Copy Copy Copy Copy Copy"];
    cellT.lineLabel.text = @"-----------------------------------------------------------------";
    return cellT;
}

// 返回cell高度
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    self.indexP = indexPath.row;
    return 47;
    
}
// 点击cell
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"播放cell");
    
    self.playUId = self.twiceArr[indexPath.row][@"id"];;
    NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithObject:self.playUId forKey:@"id"];
    NSNumber *num = [NSNumber numberWithUnsignedInteger:indexPath.row];
    [dic setObject:num forKey:@"index"];
    [[NSNotificationCenter defaultCenter]postNotificationName:@"tagValue" object:nil userInfo:dic];
}


- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
